<?php
//职位控制器
class PositionAction extends CommonAction {
		/**
		 * [positionList description]职位列表
		 * @return [type] [description]
		 */
		public function positionList(){
			$this->departmentSelect=$this->getDeparmentSelect();

			$data=$this->getAllDepartment();
	        $tree=$this->createTreeStuctDpt($data);
	        $json=$this->createSelectHtml($tree);
	        $this->assign('json',$json);
			$this->display("Position:positionList");
		}


		/**
	     * [positionData description]获取列表
	     * @return [type] [description]
	     */
	    public function positionData(){
	    	$result = array();
	    	$result['total'] = $this->getListCount();
	    	$result['rows'] = $this->getList();
	    	echo json_encode($result);
	    }

	    /**
	     * 获取列表
	     */
	    public function getList(){
	    	import("ORG.Util.Page");
	    	$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
	    	$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
	    	$model=M('Model');
			$result=$model->table('oa_position op,oa_department od')->where("op.position_dpt_id=od.dpt_id")->page($page,$rows)->select();
	        return $result;
	    }
	    
	    /**
	     * 获取列表数量
	     */
	    public function getListCount(){	
	    	$model=M('Model');
			$result=$model->table('oa_position op,oa_department od')->where("op.position_dpt_id=od.dpt_id")->count();
	        return $result;
	    }

	    /**
	     * [addPositionPost description]添加职位处理
	     */
		public function addPositionPost(){
			$position=M('Position');
			$position->position_name=I('position_name');
			$position->position_dpt_id=I('position_dpt_id');
			if($position->add()){
				echo 'ok';
			}
			else{
				echo 'no';
			}
		}

		/**
		 * [editPositionPost description]修改职位处理
		 * @return [type] [description]
		 */
		public function editPositionPost(){
			$position=M('Position');
			$data['position_name']=I('position_name');
			$data['position_dpt_id']=I("position_dpt_id");
			$result=$position->where("position_id='".I('position_id')."'")->save($data);
			if($result!=false){
	            echo 'ok';
	        }
	        else{
	            echo 'no';
	        }
		}
		
		/**
		 * [delPositionPost description]删除职位
		 * @return [type] [description]
		 */
		public function delPositionPost(){
			$position_id=I('position_id');
			$position=M('Position');
			$result=$position->where("position_id ='".$position_id."'")->delete();
	        if($result){
	            echo 'ok';
	        }
	        else{
	            echo 'no';
	        }
		}


}
